<!-- Teacher_TrainDetail.html -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>培训详情win</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
    <link rel="stylesheet" href="../../css/CFNetPP_Base.css">
    <style type="text/css">
        .base_content_div{
            padding: 10px;
            padding-bottom: 60px;
        }
        .footer-view{
            position: fixed;
            left: 0;
            bottom: 0;
            margin: 0;
            width: 100%;
            height: 50px;
            padding: 0;
        }
        .footer-view .mui-btn-block{
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            background-color: #ff9900;
            border-color: #ff9900;
            color: white;
            font-size: 16px;
        }
        .footer-view .mui-btn-block:active{
            background-color: #ff9900;
        }
        .footer-view .disabled-btn{
            background-color: #e0e0e0;
            border-color: #e0e0e0;
            color: #ff9900;
        }
        .footer-view .disabled-btn:active{
            background-color: #e0e0e0;
            border-color: #e0e0e0;
            color: #ff9900;
        }
    </style>
</head>
<body>
    <div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
    <div class="base_navigation_bar base_style_color base_navigation_item_bar">
        <a class="base_left_item" href="#" onclick="backClick()">
            <img class="base_back_icon" src="../../image/icon_jiantou.png" alt="">
        </a>
        <span id="nav_title"></span>
        <a class="base_right_item base_hide_item">
        </a>
    </div>
    <div id="train_detail" class="base_content_div">
    </div>
    <div class="footer-view" hidden="hidden">
        <!-- <button id="signUpBtn" type="button" class="mui-btn mui-btn-block">我要报名</button> -->
        <button id="signUpBtn" type="button" class="mui-btn mui-btn-block disabled-btn">已结束</button>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript">
    var uid;
    var jid;
    apiready = function(){
        SendBehaviorTrajectoriesNotifi1('0', '培训详情页', '137','widget://html/Teacher_Teach/Teacher_TrainListWin.html', '培训首页', 'widget://html/Teacher_Teach/Teacher_TrainDetail.html', '培训详情win');
        prepareData();
        setupTrainDetail();
        setRefreshSignStatusNotifi();
    }
    function prepareData(){
        uid = $api.getStorage('cfnetppuid');
        jid = $api.getStorage('cfnetppjxid');
        if (jid == null || jid == undefined) {
            jid = '158';
        }
    }
    function setRefreshSignStatusNotifi(){
        api.addEventListener({
            name: 'viewappear'
        }, function(ret, err) {
            // var url = api.pageParam.trianurl;
            // if (url == null) {
            //     return;
            // }
            var aid = api.pageParam.aid;
            if (aid == null) {
                return;
            }
            var param = {
                uid : uid,
                jid : jid,
                aid : aid
            };
            cfnetppPOST(url_getTrainSignUpStatus, param, false, function(data, status){
                if (status == 'success') {
                    if (data.status == true) {
                        var signUpStatus = data.data.signUpStatus;
                        var signUpUrl = data.data.signUpUrl;
                        setupSignUpBtn(signUpStatus, signUpUrl);
                    }
                }
            });
        });
    }
    function setupTrainDetail(){
        var pageparam = api.pageParam;
        $('#nav_title').text(pageparam.title);
        var trianurl = pageparam.trianurl;
        if (trianurl == null || trianurl == undefined || trianurl == '') {//如果没有详情链接则直接在当前页面显示html内容
            $('#train_detail').html(escape2Html(pageparam.content));
            setupImage();
        }else{//打开子页面跳转链接
            setupSubframe(trianurl);
        }
        // var signUpStatus = api.pageParam.signUpStatus;
        // setupSignUpBtn(signUpStatus, null);
        // $('.footer-view').show();
    }
    function setupSignUpBtn(signUpStatus, signUpUrl){
        if (signUpStatus == 0) {//未报名
            $('#signUpBtn').text('我要报名');
            $('#signUpBtn').removeClass('disabled-btn');
            $('#signUpBtn').click(function(){
                onSignUp(signUpStatus, signUpUrl);
            });
        }else if(signUpStatus == 1){//已报名
            $('#signUpBtn').text('已报名');
            $('#signUpBtn').addClass('disabled-btn');
            $('#signUpBtn').click(function(){
                onSignUp(signUpStatus, signUpUrl);
            });
        }else{//已过期
            $('#signUpBtn').text('已结束');
            $('#signUpBtn').addClass('disabled-btn');
            $('#signUpBtn').unbind('click');
        }
        $('.footer-view').show();
    }
    function setupSubframe(pageurl){
        var y = $('#BarAppearance').height() + $('.base_navigation_bar').height();
        var h = api.winHeight - y - $('.footer-view').height();
        api.openFrame({
            name: 'trainDetail',
            url: pageurl,
            rect: {
                x: 0,
                y: y,
                w: 'auto',
                h: h
            },
            bounces: false,
            progress:{//设置进度条类型和样式
                type:'page',
                color:'#18b4ed'
            }
        });
    }
    function backClick(){
        SendBehaviorTrajectoriesNotifi1('1', '培训详情页', '137','widget://html/Teacher_Teach/Teacher_TrainListWin.html', '培训首页', 'widget://html/Teacher_Teach/Teacher_TrainDetail.html', '培训详情win');
        api.closeWin();
    }
    function escape2Html(str) {
        var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
        return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
    }
    function setupImage() {
        var newWidth = api.winWidth - 20;
        $("img").each(function(i) {
            var oldWith = $(this).width();
            if (oldWith == 0) {
                setTimeout(function() {
                    setupImage();
                }, 500);
                return;
            }
            if (oldWith > newWidth) {
                var oldHeight = $(this).height();
                var newHeight = oldHeight * (newWidth / oldWith);
                $(this).width(newWidth);
                $(this).height(newHeight);
            }
        });
    }
    function onSignUp(signUpStatus, signUpUrl) {
        if (api.connectionType == "none") {
            api.toast({
                msg: '网络异常，请检查网络！'
            });
            return;
        }
        var param = api.pageParam;
        param['signUpStatus'] = signUpStatus;
        param['signUpedUrl'] = signUpUrl;
        param['lastPageUrl'] = 'widget://html/Teacher_Teach/Teacher_TrainDetail.html';
        param['lastPageName'] = '培训详情win';
        api.openWin({useWKWebView:true,
            name: 'Teacher_TrainSignUp',
            url: 'Teacher_TrainSignUp.html',
            pageParam: param
        });
    }
</script>
</html>
